package tagdiy;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

/**
 *
 * tagdiy
 * 快速入门：使用自定义标签，显示客户机的ip地址
 * 2018/5/17-7:18
 * 2018
 * Created by wuqiang on 2018/5/17.
 */
public class ViewIpTag extends TagSupport {
    @Override
    public int doStartTag() throws JspException {
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        String remoteAddr = request.getRemoteAddr();
        try {
            pageContext.getOut().write(remoteAddr);//显示 客户端的ip地址
        } catch (IOException e) {
            e.printStackTrace();
        }
        return super.doStartTag();
    }
}
